﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class User_Employer_EditVillage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LblStatus.Text = "";
    }
    protected void BtnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            DropDownList dp = (DropDownList)SelectCity1.FindControl("DropDownVillage");
            IDataReader dr = DataAccess.TblVillage.FetchByParameter("ID", SubSonic.Comparison.Equals,dp.SelectedItem.Value);
            dr.Read();
            MultiView1.ActiveViewIndex = 1;
            TxtVillageName.Text = dr["Name"].ToString();
            TxtVillageCode.Text = dr["VillageCode"].ToString();
            TxtKhanevar.Text = dr["Khanevar"].ToString();
            TxtPopulation.Text = dr["Population"].ToString();
            dr.Close();
        }
        catch
        {
            LblStatus.Text = " <script>alert('.بارگذاری با خطا مواجه شد')</script>";
            MultiView1.ActiveViewIndex =0;
        }
    }
    protected void BtnRegister_Click(object sender, EventArgs e)
    {
        try
        {
            //int vilcode= Convert.ToInt32 (TxtVillageCode.Text);
            //  int khanevar=Convert.ToInt32(TxtKhanevar.Text);
            //  int population=Convert.ToInt32(TxtPopulation.Text);
            //  DataAccess.TblVillage v = new DataAccess.TblVillage();
            //  DataAccess.TblVillage.Update(id,vilcode,TxtVillageName.Text,TxtShahrestan.Text,TxtDehestan.Text,TxtBakhsh.Text,khanevar,population);
            DropDownList dp = (DropDownList)SelectCity1.FindControl("DropDownVillage");
            SubSonic.Query q = DataAccess.TblVillage.CreateQuery();
            q.QueryType = SubSonic.QueryType.Update;
            q.AddUpdateSetting(DataAccess.TblVillage.Columns.VillageCode, TxtVillageCode.Text);
            q.AddUpdateSetting(DataAccess.TblVillage.Columns.Name, TxtVillageName.Text);
            //q.AddUpdateSetting(DataAccess.TblBakhsh., TxtShahrestan.Text);
            //q.AddUpdateSetting(DataAccess.TblVillage.Columns.Dehestan, TxtDehestan.Text);
            //q.AddUpdateSetting(DataAccess.TblVillage.Columns.Bakhsh, TxtBakhsh.Text);
            q.AddUpdateSetting(DataAccess.TblVillage.Columns.Khanevar, TxtKhanevar.Text);
            q.AddUpdateSetting(DataAccess.TblVillage.Columns.Population, TxtPopulation.Text);
            q.AddWhere("ID", SubSonic.Comparison.Equals, dp.SelectedItem.Value);
            q.Execute();
            LblStatus.Text = ".ویرایش روستا با موفقیت انجام شد";
            LblStatus.CssClass = "success";
            MultiView1.ActiveViewIndex = 0;
            dp.ClearSelection();
           
        }
        catch
        {
            LblStatus.Text = " .ویرایش روستا با خطا مواجه شد";
            MultiView1.ActiveViewIndex = 0;
            LblStatus.CssClass = "error";
        }
    }
    protected void BtnCancel_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 0;
    }
   
}